package yhk;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DiscoveryController {

    @NacosInjected
    private NamingService namingService;

    /**
     * 注入远程配置中心的配置文件 application申明dataid groupid
     */
    @NacosValue(value = "${test1}", autoRefreshed = true)
    private String test1;


    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public String get() {
        return test1;
    }

    @RequestMapping(value = "/get1", method = RequestMethod.GET)
    @ResponseBody
    public List<Instance> get1(@RequestParam String serviceName) throws NacosException {
        return namingService.getAllInstances(serviceName);
    }

}
